package com.ruoyi.web.controller.rgpp;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.rgpp.domain.JmrJibencompany;
import org.apache.commons.math3.ml.neuralnet.twod.util.TopographicErrorHistogram;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.rgpp.domain.JmrJibenstudents;
import com.ruoyi.rgpp.service.IJmrJibenstudentsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 学生基本信息Controller
 *
 * @author ruoyi
 * @date 2022-06-13
 */
@Controller
@RequestMapping("/rgpp/jibenstudents")
public class JmrJibenstudentsController extends BaseController
{
    private String prefix = "rgpp/jibenstudents";

    @Autowired
    private IJmrJibenstudentsService jmrJibenstudentsService;

    @RequiresPermissions("rgpp:jibenstudents:view")
    @GetMapping()
    public String jibenstudents()
    {
        return prefix + "/jibenstudents";
    }

    /**
     * 查询学生基本信息列表
     */
    @RequiresPermissions("rgpp:jibenstudents:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JmrJibenstudents jmrJibenstudents)
    {
        startPage();
        List<JmrJibenstudents> list = jmrJibenstudentsService.selectJmrJibenstudentsList(jmrJibenstudents);
        return getDataTable(list);
    }

    /**
     * 导出学生基本信息列表
     */
    @RequiresPermissions("rgpp:jibenstudents:export")
    @Log(title = "学生基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JmrJibenstudents jmrJibenstudents)
    {
        List<JmrJibenstudents> list = jmrJibenstudentsService.selectJmrJibenstudentsList(jmrJibenstudents);
        ExcelUtil<JmrJibenstudents> util = new ExcelUtil<JmrJibenstudents>(JmrJibenstudents.class);
        return util.exportExcel(list, "学生基本信息数据");
    }

    /**
     * 导入学生基本信息列表
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<JmrJibenstudents> util = new ExcelUtil<JmrJibenstudents>(JmrJibenstudents.class);
        List<JmrJibenstudents> JmrJibenstudentList = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getSysUser().getLoginName();
        String message = jmrJibenstudentsService.importJibenstudents(JmrJibenstudentList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<JmrJibenstudents> util = new ExcelUtil<JmrJibenstudents>(JmrJibenstudents.class);
        return util.importTemplateExcel("用户数据");
    }


    /**
     * 新增学生基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存学生基本信息
     */
    @RequiresPermissions("rgpp:jibenstudents:add")
    @Log(title = "学生基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JmrJibenstudents jmrJibenstudents)
    {
        return toAjax(jmrJibenstudentsService.insertJmrJibenstudents(jmrJibenstudents));
    }

    /**
     * 修改学生基本信息
     */
    @RequiresPermissions("rgpp:jibenstudents:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JmrJibenstudents jmrJibenstudents = jmrJibenstudentsService.selectJmrJibenstudentsById(id);
        mmap.put("jmrJibenstudents", jmrJibenstudents);
        return prefix + "/edit";
    }

    /**
     * 修改保存学生基本信息
     */
    @RequiresPermissions("rgpp:jibenstudents:edit")
    @Log(title = "学生基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JmrJibenstudents jmrJibenstudents)
    {
        return toAjax(jmrJibenstudentsService.updateJmrJibenstudents(jmrJibenstudents));
    }

    /**
     * 删除学生基本信息
     */
    @RequiresPermissions("rgpp:jibenstudents:remove")
    @Log(title = "学生基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jmrJibenstudentsService.deleteJmrJibenstudentsByIds(ids));
    }
}